package org.collector.process;

import java.util.Random;
import java.util.Vector;

import org.collector.DownloadPageRun;
import org.collector.data.iodata.FailPage;
import org.collector.data.iodata.IUrl;
import org.workstream.ZDataNode;
import org.workstream.ZSuperProcessNode;

public abstract class TaskFailProc extends ZSuperProcessNode {
	private Vector<TaskAllocRunable> vct_TaskAllocRunables;
	public TaskFailProc(int pthreadNum,DownloadPageRun run) {
		super(pthreadNum);
		// TODO Auto-generated constructor stub
		this.vct_TaskAllocRunables = run.getVct_taskAllocs();
		super.getDealDataTypeSet().add(FailPage.class);
	}

	@Override
	protected void processData(ZDataNode arg0) {
		// TODO Auto-generated method stub
		if(arg0 instanceof FailPage){
			deal((FailPage)arg0);
		}
	}
	
	protected Vector<TaskAllocRunable> getVct_TaskAllocRunables() {
		return vct_TaskAllocRunables;
	}
	protected boolean addTask(IUrl urlnode){
		int index = new Random(System.currentTimeMillis()).nextInt(vct_TaskAllocRunables.size());
		return vct_TaskAllocRunables.get(index).addTask(urlnode);
	}
	protected abstract void deal(FailPage node);
}
